package com.mingtu.jgspatrol.activity;

import android.view.View;

import com.mingtu.common.utils.ActivityUtil;
import com.mingtu.common.utils.StatusBarUtil;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.adapter.PhotoAdapter;
import com.mingtu.jgspatrol.base.MyBaseActivity;
import com.mingtu.jgspatrol.databinding.ActivityPhotoViewBinding;
import com.mingtu.infrared.bean.InfraredRecordImgBean;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.List;

public class PhotoViewActivity extends MyBaseActivity<ActivityPhotoViewBinding> {
    private List<InfraredRecordImgBean.DataBean.ListBean> listBeans;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_photo_view;
    }

    @Override
    protected void initView() {
        hideHeadView();
        StatusBarUtil.addStatusBarHeight(binding.statusBarView);
    }

    @Override
    protected void initData() {
        //前面已经做了 判空逻辑
        listBeans = (List<InfraredRecordImgBean.DataBean.ListBean>) getIntent().getSerializableExtra("list");
        int position = getIntent().getIntExtra("positon", 0);

        setCurrentTitle((position + 1));

        PhotoAdapter photoAdapter = new PhotoAdapter(context, listBeans);
        binding.banner.isAutoLoop(false); //是否允许自动轮播
        binding.banner.setAdapter(photoAdapter, true);
        binding.banner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                setCurrentTitle((position + 1));
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        addClickListener(this, binding.ivBack);
    }

    @Override
    protected void getData() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_back:
                ActivityUtil.removeActivity(this);
                break;
        }
    }


    private void setCurrentTitle(int position) {

        if (listBeans != null) {
            if (listBeans.size() > 0) {
                binding.tvTitle.setText((position + 1) + "/" + listBeans.size());
            }
        }

    }
}